//index.js
const Controllers = require('../../controllers/Controller.js').controller;
const utils = require('../../../utils/util.js');
const app = getApp();
Page({
  data: {
    statistics: [
      {
        value: 0,
        key: 'shopNum',
        text: '招商数量',
        unit: '',
        color: '',
      },
      {
        value: 0,
        key: 'commission',
        text: '提成金额',
        unit: '¥',
        color: ''
      },
      {
        value: 0,
        key: 'withdrawal',
        text: '员工提现总额',
        unit: '¥',
        color: '#F50E0E',
      }
    ],
    agentStaffId: ''
  },
  onLoad(options) {
    var that = this;
    that.setData({
      agentStaffId: options.id
    })
  },
  onShow() {
    var that = this;
    that.staffIndex();
    that.staffDetail();
  },
  staffIndex() {
    Controllers.staffIndex({}).then(res => {
      console.log('staffIndex--res==', res);
      const { code, data, desc } = res;
      
    })
  },
  staffDetail() {
    var that = this;
    var agentStaffId = that.data.agentStaffId;
    Controllers.staffDetail({agentStaffId}).then(res => {
      console.log('staffDetail--res==', res);
      const { code, data, desc } = res;
      var now = new Date();
      const Y = now.getFullYear();
      const M = now.getMonth() + 1 > 9 ? now.getMonth() + 1 : '0' + now.getMonth() + 1;
      var toMonth = { ...data.toMonth, createTime: `${Y}-${M}`};

      that.setData({
        statistics: that.data.statistics,
        details: data,
        toMonth,
        list: data.commissionList
      })
    })
  },
  getInput(e) {
    var that = this;
    var name = e.target.dataset.name;
    var value = e.detail.value;
    var formData = that.data.formData;
    if (name === 'phone') {
      if (value.length === 11) {
        if (!utils.checkPhone(value)) {
          wx.showToast({
            title: '手机号码格式不正确',
            icon: 'none'
          });
          return;
        } else {
          formData[name] = value;
          that.setData({
            formData
          });
        }
      }
      return;
    }
    formData[name] = value;
    that.setData({
      formData
    })
    console.log('that.data.formData==', that.data.formData);
  },
  openPage(e) {
    var url = e.currentTarget.dataset.url;
    if (url) {
      app.openPage({ url });
    } else {
      wx.showToast({
        title: '未获取页面路径',
        icon: 'none'
      });
    }
  }
})